local xiongtun = fk.CreateSkill{
    name = "lingling__xiongtun",
}
Fk:loadTranslationTable{
    ["lingling__xiongtun"] = "雄吞",
    [":lingling__xiongtun"] = "出牌阶段限一次/当你使用【杀】指定目标后，你可以与一名其他角色/目标角色拼点，若你赢，你获得其拼点牌，若你没赢，你们获得对方的拼点牌。",
    ["#lingling__xiongtun-invoke"] = "是否发动 雄吞，与 %dest 拼点",
}

xiongtun:addEffect("active", {
    max_phase_use_time = 1,
    can_use = function (self, player)
        return self:withinTimesLimit(player, Player.HistoryPhase) and not player:isKongcheng()
    end,
    card_num = 0,
    target_num = 1,
    card_filter = Util.FalseFunc,
    target_filter = function(self, player, to_select, selected, selected_cards)
        return #selected == 0 and to_select ~= player and player:canPindian(to_select)
    end,
    on_use = function(self, room, effect)
        local player = effect.from
        local target = effect.tos[1]
        local pindian = player:pindian({target}, xiongtun.name)
        local winner = pindian.results[target].winner
        if winner == player then
            if not player.dead and pindian.results[target] and pindian.results[target].toCard and
                room:getCardArea(pindian.results[target].toCard) == Card.DiscardPile then
                room:moveCardTo(pindian.results[target].toCard, Card.PlayerHand, player, fk.ReasonJustMove, xiongtun.name, nil, true, player)
            end
        else
            local moveInfos = {}
            if pindian.results[target].toCard and not player.dead and
            room:getCardArea(pindian.results[target].toCard) == Card.DiscardPile then
                table.insert(moveInfos, {
                    to = player,
                    ids = Card:getIdList(pindian.results[target].toCard),
                    toArea = Card.PlayerHand,
                    moveReason = fk.ReasonExchange,
                    proposer = player,
                    skillName = xiongtun.name,
                })
            end
            if pindian.fromCard and not target.dead and
            room:getCardArea(pindian.fromCard) == Card.DiscardPile then
                table.insert(moveInfos, {
                    to = target,
                    ids = Card:getIdList(pindian.fromCard),
                    toArea = Card.PlayerHand,
                    moveReason = fk.ReasonExchange,
                    proposer = player,
                    skillName = xiongtun.name,
                })
            end
            if #moveInfos > 0 then
                room:moveCards(table.unpack(moveInfos))
            end
        end
    end,
})

xiongtun:addEffect(fk.TargetSpecified, {
    can_trigger = function(self, event, target, player, data)
        return
        target == player and
        player:hasSkill(xiongtun.name) and
        data.card and
        data.card.trueName == "slash" and
        player:canPindian(data.to)
    end,
    on_cost = function (self, event, target, player, data)
        if player.room:askToSkillInvoke(player,{
            skill_name = xiongtun.name,
            prompt = "#lingling__xiongtun-invoke::" .. data.to.id,
        }) then
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local to = data.to
        local pindian = player:pindian({to}, xiongtun.name)
        local winner = pindian.results[to].winner
        if winner == player then
            if not player.dead and pindian.results[to] and pindian.results[to].toCard and
                room:getCardArea(pindian.results[to].toCard) == Card.DiscardPile then
                room:moveCardTo(pindian.results[to].toCard, Card.PlayerHand, player, fk.ReasonJustMove, xiongtun.name, nil, true, player)
            end
        else
            local moveInfos = {}
            if pindian.results[to].toCard and not player.dead and
            room:getCardArea(pindian.results[to].toCard) == Card.DiscardPile then
                table.insert(moveInfos, {
                    to = player,
                    ids = Card:getIdList(pindian.results[to].toCard),
                    toArea = Card.PlayerHand,
                    moveReason = fk.ReasonExchange,
                    proposer = player,
                    skillName = xiongtun.name,
                })
            end
            if pindian.fromCard and not to.dead and
            room:getCardArea(pindian.fromCard) == Card.DiscardPile then
                table.insert(moveInfos, {
                    to = to,
                    ids = Card:getIdList(pindian.fromCard),
                    toArea = Card.PlayerHand,
                    moveReason = fk.ReasonExchange,
                    proposer = player,
                    skillName = xiongtun.name,
                })
            end
            if #moveInfos > 0 then
                room:moveCards(table.unpack(moveInfos))
            end
        end
    end,
})

return xiongtun